package com.jzy.message.activities.base;

import android.app.Dialog;
import android.content.Context;
import android.support.v4.app.Fragment;

import com.jzy.message.util.common.CommUtility;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

/**
 * Created by Administrator on 2016/6/23.
 */
public class BaseFragment extends Fragment {
    public BaseFragment thisFragment;
    public Dialog dlgWaiting;
    public void requestDataGet(final int flag, final Context context, RequestParams params)
    {
        if(!AppConfig.sCurrentCookie.equals(""))
        {
            params.setUseCookie(false);
            params.addHeader("Cookie",AppConfig.sCurrentCookie);
        }
        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onCancelled(CancelledException arg0) {
                if(dlgWaiting!=null&&dlgWaiting.isShowing())
                {
                    dlgWaiting.hide();
                    CommUtility.showmsg(context, "数据加载取消");
                }
            }
            @Override
            public void onError(Throwable arg0, boolean arg1) {
                if(dlgWaiting!=null&&dlgWaiting.isShowing())
                {
                    dlgWaiting.hide();
                    CommUtility.showmsg(context, "数据加载错误"+arg0);
                }
            }
            @Override
            public void onFinished() {
                if(dlgWaiting!=null&&dlgWaiting.isShowing())
                {
                    dlgWaiting.hide();
                }
            }
            @Override
            public void onSuccess(String arg0) {
                dlgWaiting.hide();
                ParseData(flag, arg0);
            }
        });
    }
    public void requestDataPost(final int flag,final Context context,RequestParams params)
    {
        if(!AppConfig.sCurrentCookie.equals(""))
        {
            params.setUseCookie(false);
            params.addHeader("Cookie",AppConfig.sCurrentCookie);
        }
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onCancelled(CancelledException arg0) {
                if(dlgWaiting!=null&&dlgWaiting.isShowing())
                {
                    dlgWaiting.hide();
                    CommUtility.showmsg(context, "数据加载取消");
                }
            }
            @Override
            public void onError(Throwable arg0, boolean arg1) {
                if(dlgWaiting!=null&&dlgWaiting.isShowing())
                {
                    dlgWaiting.hide();
                    CommUtility.showmsg(context, "数据加载错误");
                }
            }
            @Override
            public void onFinished() {
                if(dlgWaiting!=null&&dlgWaiting.isShowing())
                {
                    dlgWaiting.hide();
                }
            }
            @Override
            public void onSuccess(String arg0) {
                dlgWaiting.hide();
                ParseData(flag, arg0);
            }
        });
    }
    public void ParseData(int flag,String jsonstr)
    {

    }
}
